// Don't forget to add version.lib to the linker list of import libraries.

#include <windows.h>
#include <iostream.h>

int main(int argc, char* argv[])
{
	if(argc < 2)
	{
		cout << "A file name is required." << endl;
		return E_FAIL;
	}

	cout << "Testing " << argv[1] << endl;

	DWORD dwhandle;
	DWORD size = GetFileVersionInfoSize(argv[1], &dwhandle);
	if(size == 0)
	{
		cout << "GetFileVersionInfoSize failed." << endl;
		return E_FAIL;
	}

	void* pData = new BYTE[size];

	BOOL ret = GetFileVersionInfo(argv[1], 0, size, pData);
	if(ret == 0)
	{
		cout << "GetFileVersionInfo failed." << endl;
		return E_FAIL;
	}

	DWORD* pBuffer;
	UINT length = 0;

	ret = VerQueryValue(pData, "\\VarFileInfo\\Translation", (void**)&pBuffer, &length);
	if(ret == 0)
	{
		cout << "VerQueryValue failed." << endl;
		return E_FAIL;
	}

	char pString[256];
    wsprintf(pString, "\\StringFileInfo\\%04hX%04hX\\OLESelfRegister", LOWORD(*pBuffer), HIWORD(*pBuffer));
	cout << "Looking for " << pString << endl;

   	ret = VerQueryValue(pData, pString, (void**)&pBuffer, &length);
	if(ret == 0)
		cout << "This is not a self-registering component." << endl;
	else
		cout << "This is a self-registering component." << endl;

	delete pData;
	return ret;
}